﻿/*!
* File Name: MyAccount.js
* Created When:     2012-03-22
* Created by:       陈鹏
* Created Whys:     
*/


/*公共方法*/
/*CommonFunctionBegin*/
//转换时间格式
function renderTime(data) {
    if (data == null || typeof data == "undefined") return "";
    var date = new Date(parseInt(data.replace("/Date(", "").replace(")/", ""), 10));
    var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
    var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
    var s = currentDate + "/" + month + "/" + date.getFullYear();
    if (date.getHours() == 0 && date.getMinutes() == 0)
        return s;
    else
        return s + " " + date.getHours() + ":" + date.getMinutes();
}

/*CommonFunctionEnd*/

/*我的评论和上传--Begin--*/
//ajax请求我的活动评论数据    getMyAccount（语言，当前页，每页个数）
function getMyAccount(langID, pageIndex, pageSize,memberID) {
    var url = '/GateService/AjaxHttpGate.aspx?cmd=myAccountPaging&langID=' + langID + '&currentPagingIndex=' + pageIndex + '&pagingsize=' + pageSize + '&memberID=' + memberID + '&random=' + new Date().toLocaleString();
    var req = new ajaxRequest(url);
    req.async = false;
    req.get(function (data) {
        showMyAccountList(data, pageSize, langID, pageIndex);
    });
}

//ajax请求 删除活动评论
function delEventCommentsByID(langID, pageIndex, pageSize, memberID, eventCommentID) {
    var url = '/GateService/AjaxHttpGate.aspx?cmd=delEventComment&langID=' + langID + '&eventCommentID=' + eventCommentID + '&random=' + new Date().toLocaleString();
    var req = new ajaxRequest(url);
    req.async = false;
    req.get(function (res) {
        if (res != null && res.Result) {
            getMyAccount(langID, pageIndex, pageSize, memberID);
        }
        if (res == null || !res.Result) {
            if (langID == 2052)
                alert('删除失败!/n');
            else
                alert('Delect Failed!/n');
        }
    });
 
}
//显示我的评论列表  showMyAccountList(数据源，每页个数，语言，当前页）
function showMyAccountList(pagingList, pageSize, langID, pageIndex, memberID) {
    $('#mainId').html("");
    $('#pageFoot').html("");
    var total = pagingList.Capacity; //总数
    if (total > 0) {
        var length = pagingList.List.length;
        for (var i = 0; i < length; i++) {
            renderMainHtml(pagingList.List[i],total);
        }
        showFoot(total, pageSize, langID, pageIndex, memberID);
    }
}
//输出Html
function renderMainHtml(model,total) {
    var html = $('#mainId');
    var imgSrc = "/uploadfiles/cms/image/" + model.ImagePath;
    var eventID = model.Events.ID;//活动ID
    var title = model.Events.Title;  //活动标题
    var date = renderTime(model.InsertedTime);
    var desc = model.Content;
    html.append('<span>我的评论&上传（' + total + '条评论）</span>');
    html.append('<div>评论To;<a href="events/' + eventID + '.html">' + title + '</a></div>');
    html.append('<div>评论内容：' + desc + '<span>(' + date + ')</span></div>');
    html.append('<div>评论图片：<img src="' + imgSrc + '" onerror="this.src=("/uploadfiles/image/default_img.jpg")" alt="" /></div>');
    html.append('<div><a href="#">删除</a></div>');
    html.append('</div>');
}

//显示分页页脚
function showFoot(total, pageSize, langID, pageIndex, memberID) {
    var pageNum;
    if (total % pageSize)
        pageNum = Math.floor(total / pageSize);
    else
        pageNum = Math.floor(total / pageSize) + 1;
    if (pageNum != 1) {
        renderPagingFoot(langID, pageIndex, pageSize, pageNum, memberID);
    }
}
//输出分页 页脚
function renderPagingFoot(langID, pageIndex, pageSize, pageNum, memberID) {
    var html = $('#pageFoot');
    html.append('<div>');
    html.append('<span>' + (pageIndex + 1) + '/' + pageNum + '</span>');
    html.append('<a href="javascript:void(0);" style="cursor:hand" onclick="javascript:prePaging(' + langID + ',' + pageIndex + ',' + pageSize + ',' + memberID + ');">上一页</a>');
    html.append('<a href="javascript:void(0);" style="cursor:hand" onclick="javascript:nextPaging(' + langID + ',' + pageIndex + ',' + pageSize + ',' + pageNum + ',' + memberID + ');">下一页</a>');
    html.append('</div>');
}

//上一页
function prePaging(langID, pageIndex, pageSize, memberID) {
    if (pageIndex <= 1) {
        getMyAccount(langID, 0, pageSize, memberID);
    }
    else {
        getMyAccount(langID, (pageIndex - 1), pageSize, memberID);
    }

}
//下一页
function nextPaging(langID, pageIndex, pageSize, pageNum, memberID) {
    if ((pageIndex + 1) >= pageNum) {
        getMyAccount(langID, pageIndex, pageSize, memberID);
    }
    else {
        getMyAccount(langID, (pageIndex + 1), pageSize, memberID);
    }
}

/*我的评论和上传--End--*/